package miniapp

import (
	"strconv"
	"strings"

	"mall/common/globalkey"
)

func GetLinkUrl(linkType *uint32, adType *uint32, adId *uint64, linkUrl *string) string {
	if linkType != nil {
		if *linkType == uint32(globalkey.SettingBannerLinkTypeRelative) { // 小程序相对路径
			if adType != nil && *adType == uint32(globalkey.SettingBannerAdvertTypeProduct) && adId != nil && *adId > 0 {
				return "page:///pages/scentrobe/goods-detail/goods-detail-page?id=" + strconv.FormatInt(int64(*adId), 10)
			}

			if adType != nil && *adType == uint32(globalkey.SettingBannerAdvertTypePage) && linkUrl != nil && len(strings.TrimSpace(*linkUrl)) > 0 {
				return strings.TrimSpace(*linkUrl)
			}
		}
	}

	if linkUrl != nil && len(strings.TrimSpace(*linkUrl)) > 0 {
		url := strings.TrimSpace(*linkUrl)
		if strings.HasPrefix(url, "https://") {
			return url
		}

		if strings.HasPrefix(url, "http://") {
			return url
		}
	}

	return ""
}

func GetKBPostLinkUrl(id *uint64) string {
	if id != nil {
		return "page:///pages/scentrobe/package/entry-detail/entry-detail-page?id=" + strconv.FormatInt(int64(*id), 10)
	}

	return ""
}

func GetProductLinkUrl(id *uint64) string {
	if id != nil {
		return "page:///pages/scentrobe/goods-detail/goods-detail-page?id=" + strconv.FormatInt(int64(*id), 10)
	}

	return ""
}

func GetPostLinkUrl(id *uint64) string {
	if id != nil {
		return "page:///pages/scentrobe/package/post-detail/post-detail-page?id=" + strconv.FormatInt(int64(*id), 10)
	}

	return ""
}

func GetReviewLinkUrl(id *uint64) string {
	if id != nil {
		return "page:///pages/scentrobe/package/forum/post-detail/post-detail-page?id=" + strconv.FormatInt(int64(*id), 10)
	}

	return ""
}
